<?php

require_once("Controller/UserController.php");
require_once("Controller/LoginController.php");
require_once("View/PageView.php");
require_once("View/NavigationView.php");
require_once("Model/Database.php");
require_once("Model/TopicList.php");
require_once("Model/LoginHandler.php");
require_once("Controller/TopicListController.php");
require_once("Controller/TopicController.php");
require_once("DBConfig.php");

class MasterController 
{
        public static function doControll() 
        {
        	//Öppnar databas
        	$db = new Database();
        	$db->Connect(new DBConfig());
								
        	//Skapar instanser
        	$lh = new LoginHandler($db);		
			$lc = new LoginController();
			$uc = new UserController();
			$tlc = new TopicListController();
			$tc = new TopicController();
			$tl = new TopicList($db);
			
			$nv = new NavigationView();
			$pw = new PageView();
			$html = "";
			$login = "";
			
			if($nv->isViewingRegisterForm() == TRUE)
			{
				$html .= $uc->DoControll($db, $lh);
				$login .= $lc->DoControll($db);  
			}
			else if($nv->isViewingTopic() == TRUE)
			{
				$login .= $lc->DoControll($db);  
				$html .= $tc->DoControll($db, $tl);
			}
			else
			{
				$login .= $lc->DoControll($db);  
				$html .= $tlc->doControll($db);
			}
				
			//Stänger databas  
			$db->Close();
			                                 
            return $pw->GetHTMLPage("Forum", $login, $html);
        }
        
}

echo MasterController::doControll();

?>
